package com.shouhuobao.bhi.loc;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.mapapi.search.core.PoiInfo;
import com.collectplus.express.R;

import droid.frame.activity.base.BaseAdapterExt;

public class ChangeAddressAdapter extends BaseAdapterExt<PoiInfo> {

	private List<PoiInfo> mList;
	private int mSelectItem = -1;

	public ChangeAddressAdapter(Activity context, ArrayList<PoiInfo> items) {
		super(items, context);
	}

	public void setSelect(int select) {
		mSelectItem = select;
	}

	public int getSlect() {
		return mSelectItem;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if (convertView == null) {
			viewHolder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.item_change_address, parent, false);
			viewHolder.tvTop = (TextView) convertView.findViewById(R.id.item_change_address_tv1);
			viewHolder.tvBottom = (TextView) convertView.findViewById(R.id.item_change_address_tv2);
			viewHolder.mImg = (ImageView) convertView.findViewById(R.id.item_change_address_img);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}

		// if (isSetColor) {
		// if (position == 0) {
		// viewHolder.tvTop.setTextColor(0xff47c6b9);
		// } else {
		// viewHolder.tvTop.setTextColor(0xde000000);
		// }
		// }
		PoiInfo item = getItem(position);
		viewHolder.tvTop.setText(item.name);
		viewHolder.tvBottom.setText(item.address);

		if (position == mSelectItem) {
			viewHolder.mImg.setVisibility(View.VISIBLE);
		} else {
			viewHolder.mImg.setVisibility(View.GONE);
		}

		return convertView;
	}

	private class ViewHolder {
		private TextView tvTop;
		private TextView tvBottom;
		private ImageView mImg;
	}

}
